package com.foreveross.crawl.common.util;

import java.io.Reader;
import java.sql.Clob;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class StringUtils extends org.apache.commons.lang3.StringUtils {

	public static String trimEmpty(String str){
		return StringUtils.isNotBlank(str) ? str.trim() : "";
	}
	private static Pattern p = Pattern.compile("\\s*|\t|\r|\n");
	public static String replaceBlank(String str) {
        String dest = null;
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        return dest;
    }
	
	public static String clobToString(Clob clob) {
	    if (clob == null)
	        return null;
	 
	    StringBuffer sb = new StringBuffer(65535);// 64K
	    Reader clobStream = null;
	    try {
	        clobStream = clob.getCharacterStream();
	        char[] b = new char[60000];// 每次获取60K
	        int i = 0;
	        while ((i = clobStream.read(b)) != -1) {
	            sb.append(b, 0, i);
	        }
	    } catch (Exception ex) {
	        sb = null;
	    } finally {
	        try {
	            if (clobStream != null) {
	                clobStream.close();
	            }
	        } catch (Exception e) {
	        }
	    }
	    if (sb == null)
	        return null;
	    else
	        return sb.toString();
	}
	
	public static Clob stringToClob(String str) {
	    if (null == str)
	        return null;
	    else {
	        try {
	            java.sql.Clob c = new javax.sql.rowset.serial.SerialClob(str
	                    .toCharArray());
	            return c;
	        } catch (Exception e) {
	            return null;
	        }
	    }
	}

	public static void main(String[] arg){
		System.out.println("111===="+UUID.randomUUID().toString());
	
		
//		Calendar cal = Calendar.getInstance();
//		cal.setTimeInMillis(1362644492823l);
//		System.out.println(DateFormatUtils.format(cal, "yyyy-MM-dd HH:mm:ss"));
	}
}
